package com.ebor.utils.utils.valid;

import com.ebor.utils.utils.EmojiUtils;
import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 不能为表情验证器
 *
 * @author C
 */
public class NotEmojiValidator implements ConstraintValidator<NotEmoji, String> {
    @Override
    public void initialize(NotEmoji constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(StringUtils.isBlank(value)) {
            return true;
        }
        return !EmojiUtils.containsEmoji(value);
    }
}
